const express = require('express')
const bodyParser = require('body-parser')
const handle = require('./api')
const app = express()
const port = 8000
app.use(
    bodyParser.urlencoded({
        extended: true
    })
)
app.use(bodyParser.json())
//设置跨域访问
app.all('*', function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Content-Type,XFILENAME,XFILECATEGORY,XFILESIZE");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By", ' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});
app.post('/carsize', (req, res) => {

    for (let handleKey in handle) {
        let newVar = handle[handleKey](req.body.api, req, res);
        if (typeof newVar === 'string') {
            return res.send(newVar);
        }
        if (typeof newVar === 'boolean') {
            return;
        }
    }
    return res.send(JSON.stringify({code: 200,message: 'asshfsdfhj'}))

})
app.get('/api', (req, res) => {
    res.send(JSON.stringify({name: 'zhangsan'}))
})
app.post('/login', (req, res) => {
    res.send(JSON.stringify({code: "1", data: 'zxcvbnm', message: '登录成功'}))
})
app.post('/HJ/JGJG', (req, res) => {
    res.send(JSON.stringify({code: '1', data: '',message: '成功'}))
})
app.post('/HJ/*', (req, res) => {
    res.send(JSON.stringify({code: '1', data: '',message: '成功'}))
})

app.listen(port, () => {
    console.log(`Example app listening at http://localhost:${port}`)
})

